package com.bflow.util;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @Name 随机工具类
 * @Author haowen
 * @Date 2018/12/13
 */
public class RandomUtil {

    public static ThreadLocalRandom getRandom() {
        return ThreadLocalRandom.current();
    }

    public static String randomString(int length) {
        return randomString("abcdefghijklmnopqrstuvwxyz0123456789", length);
    }

    public static String randomString(String baseString, int length) {
        StringBuilder sb = new StringBuilder();
        if(length < 1) {
            length = 1;
        }
        int baseLength = baseString.length();
        for(int i = 0; i < length; ++i) {
            int number = getRandom().nextInt(baseLength);
            sb.append(baseString.charAt(number));
        }
        return sb.toString();
    }
}

